//
//  RootViewController.m
//  Stock
//
//  Created by blacksun on 11-6-5.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "RootViewController.h"

@implementation RootViewController
@synthesize sectionControllers;
@synthesize sectionContainer;
@synthesize notifyView;
@synthesize tempView;
@synthesize notifyLabel;
@synthesize bannerView;

-(void)updateNotifyMessage:(int)tag{
    self.notifyView.hidden = NO;
    self.notifyLabel.textColor = [UIColor whiteColor];
    self.notifyView.alpha = 1.0;
    
    //NSLog(@"updateNotifyMessage:%d",tag);
    if(tag==0){
        self.notifyLabel.text = @"正在连接行情服务器...";
    }else if (tag==1) {
        self.notifyLabel.text = @"连接行情服务器成功";
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.5];
        self.notifyView.alpha = 0.0;
        [UIView commitAnimations];
    }else if(tag==2){
        self.notifyLabel.textColor = [UIColor redColor];
        self.notifyLabel.text = @"连接行情服务器失败";
    }else if(tag==3){
        self.notifyLabel.textColor = [UIColor redColor];
        self.notifyLabel.text = @"网络连接不可用，使用脱机模式.";
    }
}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner{
    /*NSLog(@"bannerViewDidLoadAd");
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    [UIView setAnimationDuration:3.0];
    self.bannerView.alpha = 0.0;
    [UIView commitAnimations];*/
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.sectionControllers = [NSMutableArray array];
    
    StockAppDelegate *appDelegate = [UIApplication sharedApplication].delegate; 
    for (int i=0;i<9;i++) {
        NSDictionary *stockDict  = [appDelegate.stockSections objectAtIndex:i];
        StockSectionViewController *sectionController = [[StockSectionViewController alloc] initWithNibName:@"StockSectionViewController" bundle:nil];
        sectionController.stockSection = stockDict;//stock;
        sectionController.index = i;
        sectionController.parentController = self;
        sectionController.view.frame = CGRectMake((i%3)*105.0+5.0,(i/3+i%1)*125.0,100.0,120.0);
        [self.sectionContainer addSubview:sectionController.view];
        [self.sectionControllers addObject:sectionController];
        [sectionController release];
    }
    self.title = @"掘金客";
    
    self.notifyView.layer.cornerRadius = 5;
    self.notifyView.layer.masksToBounds = YES;
    self.tempView.layer.cornerRadius = 5;
    self.tempView.layer.masksToBounds = YES;
    
    if (!IsPaidVersion) {
        
        CGRect frame = sectionContainer.frame;
        frame.origin.y = frame.origin.y-10.0;
        sectionContainer.frame = frame;
        
        self.bannerView.delegate = nil;
        [self.bannerView removeFromSuperview];
        
        ADBannerView *banner = [[ADBannerView alloc] initWithFrame:CGRectMake(0.0, 410.0, 320.0, 50.0)];
        banner.delegate = self;
        [self.view insertSubview:banner belowSubview:notifyView];
        self.bannerView = banner;
        [banner release];
    }
    
    //[self.view bringSubviewToFront:self.bannerView];
}



- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden = YES;
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    //self.bannerView.alpha = 1.0;
    
    
    

    
}

- (void)viewWillDisappear:(BOOL)animated
{
	[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
	[super viewDidDisappear:animated];
}


- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Relinquish ownership any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    self.sectionContainer = nil;
    self.notifyView = nil;
    self.tempView = nil;
    self.notifyView = nil;
    bannerView.delegate = nil;
    self.bannerView = nil;
}

- (void)dealloc
{
    [sectionControllers release];
    [sectionContainer release];
    bannerView.delegate = nil;
    self.bannerView = nil;
    self.notifyView = nil;
    self.tempView = nil;
    self.notifyLabel = nil;
    [super dealloc];
}

@end
